import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: JavaDS阶段测试
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>(20);
    }
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(1);
        while(sc.hasNextInt()) {
            int num = sc.nextInt();
            boolean flg = false;
            while(num >= list.get(list.size() - 1)) {
                int size = list.size();
                int tmp = list.get(size - 1) + list.get(size - 2);
                list.add(tmp);
                flg = true;
            }
            if(flg) {
                int size = list.size();
                int ans = Math.min(list.get(size - 1) - num , num - list.get(size - 2));
                System.out.println(ans);
            }else {
                int i = 0;
                for(; i < list.size(); i++) {
                    if(list.get(i) > num) {
                        break;
                    }
                }
                int ans = Math.min(list.get(i) - num , num - list.get(i - 1));
                System.out.println(ans);
            }
        }
    }
}
